package activity;

import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.widget.TextView;

import com.example.administrator.ci_edit.R;

import db.CipaiDatabaseHelper;
import entity.UserConfig;

/**
 * Created by Administrator on 2017/7/23.
 */


public class ZiHuaActivity extends AppCompatActivity {
    private TextView myworknameTV;
    private String myworkname;
    private TextView myworkcontentTV;
    private TextView mynameTV;
    private String myworkcontent;
    private TextView examnameTV;
    private TextView examwriterTV;
    private String examplewriter;
    private TextView examcontentTV;
    private String examplecontent;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.zihua_demo);
        Intent intent = getIntent();
        final String mywork = intent.getStringExtra("extra_mywork");
        String[] split = mywork.split("》");
        myworkname = split[0] + "》";
        myworkcontent = split[1];
        String [] myworknamepure = myworkname.split("《|》") ;

        myworknameTV = (TextView) this.findViewById(R.id.myworkname);
        myworknameTV.setText(myworkname);

        myworkcontentTV = (TextView) this.findViewById(R.id.myworkcontent);
        myworkcontentTV.setText(myworkcontent);

        mynameTV = (TextView) this.findViewById(R.id.myname);
        mynameTV.setText(UserConfig.getUsername());


        CipaiDatabaseHelper cipaiDatabaseHelper = new CipaiDatabaseHelper();
        Cursor cursor = cipaiDatabaseHelper.getExampleByCipai(myworknamepure[1]);
        while (cursor.moveToNext()){
            examplewriter = cursor.getString(cursor.getColumnIndex("author"));
            examplecontent = cursor.getString(cursor.getColumnIndex("text"));
        }

        examnameTV = (TextView)this.findViewById(R.id.examplename);
        examnameTV.setText(myworkname);

        examcontentTV = (TextView)this.findViewById(R.id.examplecontent);
        examcontentTV.setText(examplecontent);

        examwriterTV = (TextView)this.findViewById(R.id.examplewriter);
        examwriterTV.setText(examplewriter);



    }
}
